
public class Context {
    

    public void test1() {
        int count = 5;
        synchronized(this) {
            while(count > 0) {
                sleep200();
                System.out.println("test1: " + count);
                count --;
            }
        }
    }
    
    public static synchronized void test2() {
        int count = 5;
        while (count > 0) {
            sleep200();
            System.out.println("test2: " + count);
            count --;
        }
    }
    
    private static void sleep200() {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        final Context context = new Context();
        Thread thread1 = new Thread(new Runnable() {
            
            public void run() {
                // TODO Auto-generated method stub
                context.test1();
            }
        });
        Thread thread2 = new Thread(new Runnable() {
            
            public void run() {
                // TODO Auto-generated method stub
                context.test2();
            }
        });
        thread1.start();
        thread2.start();
    }
}
